package jourre;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.DSFactory;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import utils.SmallTool;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author: gcr
 * @Date: 2022-6-1 10:33
 */
public class preparedata {
    @SneakyThrows
    public static void main(String[] args) {

        Db use = Db.use(DSFactory.get("server_local"));
        String db = "pubmed_vip_extend_0328_33771437";
        String dbMerge = "jour_merge_supp";
        String insert = "nlmid_count_gcr";


        String jourmerge = "select nc_nlm_id from " + dbMerge;
        List<Entity> query = use.query(jourmerge);
        query.parallelStream().forEach(entity -> {
            String nc_nlm_id = entity.getStr("nc_nlm_id");
            if (StringUtils.isNotEmpty(nc_nlm_id)) {
                long s1 = System.currentTimeMillis();
                SmallTool.printMess("开始查询++" + nc_nlm_id);
                String count = "select count(1) as cou from " + db + " where med_nlm_id = '" + nc_nlm_id + "'";
                Integer cou = null;
                try {
                    cou = use.queryOne(count).getInt("cou");
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
                SmallTool.printMessLongTimeTake("查询++" + nc_nlm_id + "++耗时++", +s1);
                if (cou != null) {

                    try {
                        Entity entity1 = new Entity();
                        entity1.set("nlmid", nc_nlm_id);
                        entity1.set("all_count", cou);
                        entity1.setTableName(insert);
                        use.insert(entity1);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                } else {
                    try {
                        Entity entity1 = new Entity();
                        entity1.set("nlmid", nc_nlm_id);
                        entity1.set("all_count", 0);
                        entity1.setTableName(insert);
                        use.insert(entity1);
                    } catch (Exception e) {

                    }

                }
            }
        });


    }
}
